How to recognize which "case" is being echoed by switch statement

How to recognize which "case" is being echoed by switch statement

am 22.02.2008 12:01:49 von Tim Daff

--Apple-Mail-7--114873320
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit

Hi,

This is my first time using php in my site navigation, I have the code
for all the pages in one file and I am using the switch statement to
change between them.

This is working great but I am now trying to change the css id of the
current page's navbar link. How do I get my script to recognize which
case is currently being echoed by the switch statement?

If you want to see the page in action without php in the navbar visit
here: http://www.publikdesign.com


Here is the code:


























switch($_GET['page']) {

case "contact":
echo "
















";
break;

case "portfolio":
echo "




alt=\"Portfolio\" />


\"K Development Lofo\" />

\">Click to Expand
















<br \"Island Healing Logo\" />

Click
to Expand





<br \"Roaming Earth Logo\" />

Click
to Expand




";
break;

case "home":
echo "




\"Graphic Design Services\" width=\"327\" height=\"28\" />

Publik provides a full range of graphic design
services, from business cards and letterheaders, to product catalogues
and promotional brochures. We will bring your project from concept to
print in the most cost effective and professional manner.





\"Web \" />

The world wide web has grown into the most
powerful marketing tool available to a business. From a concreter to a
department store, the internet can not be overlooked as an important
tool in bringing clients to your business. Publik Design provides all
manner of web services from static pages to fully dynamic web
applications.












\"K Business Card Design\" />



<br \"Katmandog Pet Shop Thumbnail\" />


";
break;

case "kdev":
echo "




alt=\"Portfolio\" />




<br \"K Development\" />




";
break;

case "isl":
echo "




<br \"Portfolio\" />



<br \"K Development\" />





";
break;

case "re":
echo "




<br \"Portfolio\" />



\"K Development\" />




";
break;

default:
echo "




\"Graphic Design Services\" width=\"327\" height=\"28\" />

Publik provides a full range of graphic design
services, from business cards and letterheaders, to product catalogues
and promotional brochures. We will bring your project from concept to
print in the most cost effective and professional manner.





\"Web \" />

The world wide web has grown into the most
powerful marketing tool available to a business. From a concreter to a
department store, the internet can not be overlooked as an important
tool in bringing clients to your business. Publik Design provides all
manner of web services from static pages to fully dynamic web
applications.












\"K Business Card Design\" />



<br \"Katmandog Pet Shop Thumbnail\" />


";
break;

}

?>













--Apple-Mail-7--114873320--

Re: How to recognize which "case" is being echoed by switch statement

am 22.02.2008 13:31:27 von Stut

On 22 Feb 2008, at 11:01, Tim Daff wrote:
> > $page = case;
> if ( $page = "contact" ) {
> echo "

  • "; }
    >
    > else {
    > echo "
  • Contact > a>
  • "; }
    > ?>


    $page = case; will be raising a notice which you're obviously not
    seeing. So, step 1 is to edit PHP.ini on your development machine so
    error_reporting is E_ALL, and display_errors is on. You'll need to
    restart your web server for this change to take effect.

    The case keyword is not valid outside a switch block. What you want to
    be doing is comparing "contact" etc with $_GET['page'] which is the
    variable the switch statement is using.

    Additionally you are using a single = which is the assignment
    operator, so each if statement is assigning the quoted string to $page
    not testing for it. You need to use == to do that.

    I would suggest you buy a book on PHP for beginners, or Google for an
    introductory tutorial because these are pretty basic syntax mistakes.

    -Stut

    --
    http://stut.net/

    --
    PHP Database Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php

    RES: How to recognize which "case" is being echoed by switch statement

    am 22.02.2008 13:46:37 von Thiago Pojda

    Quite sure this is not what you mean:

    > $page = case;
    > if ( $page = "contact" ) {

    but instead

    > $page = case;
    > if ( $page == "contact" ) {



    -----Mensagem original-----
    De: Stut [mailto:stuttle@gmail.com]
    Enviada em: sexta-feira, 22 de fevereiro de 2008 09:31
    Para: Tim Daff
    Cc: php-db@lists.php.net
    Assunto: Re: [PHP-DB] How to recognize which 'case' is being echoed by
    switch statement

    On 22 Feb 2008, at 11:01, Tim Daff wrote:
    > > $page = case;
    > if ( $page = "contact" ) {
    > echo " id=\"contact-active\">"; }
    >
    > else {
    > echo "

  • href=\"./?page=contact\">Contact > a>
  • "; }
    > ?>


    $page = case; will be raising a notice which you're obviously not seeing.
    So, step 1 is to edit PHP.ini on your development machine so error_reporting
    is E_ALL, and display_errors is on. You'll need to restart your web server
    for this change to take effect.

    The case keyword is not valid outside a switch block. What you want to be
    doing is comparing "contact" etc with $_GET['page'] which is the variable
    the switch statement is using.

    Additionally you are using a single = which is the assignment operator, so
    each if statement is assigning the quoted string to $page not testing for
    it. You need to use == to do that.

    I would suggest you buy a book on PHP for beginners, or Google for an
    introductory tutorial because these are pretty basic syntax mistakes.

    -Stut

    --
    http://stut.net/

    --
    PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
    http://www.php.net/unsub.php

    --
    PHP Database Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php

    Re: How to recognize which "case" is being echoed by switch statement

    am 22.02.2008 16:45:41 von parasane

    On Fri, Feb 22, 2008 at 6:01 AM, Tim Daff wrote:
    > Hi,
    >
    > This is my first time using php in my site navigation, I have the code
    > for all the pages in one file and I am using the switch statement to
    > change between them.
    [snip!]

    None of your code included a case/switch piece. This is probably
    what you mean:

    $page = basename($_SERVER['PHP_SELF']);

    switch($page) {
    case "contact.php":
    $css = "

  • ";
    break;
    case "portfolio.php":
    $css = "
  • ";
    break;
    case "whoweare.php":
    $css = "
  • ";
    break;
    default:
    $css = "
  • ";
    break;
    }
    ?>

    --


    Daniel P. Brown
    Senior Unix Geek


    --
    PHP Database Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php